!-------------------------------------------------------------LICENSE--------------------------------------------------------------!
!                                                                                                                                  !
!The MAP code is written in Fortran language for magnetohydrodynamics (MHD) calculation with the adaptive mesh refinement (AMR)    !
!and Message Passing Interface (MPI) parallelization.                                                                              !
!                                                                                                                                  !
!Copyright (C) 2012                                                                                                                !
!Ronglin Jiang                                                                                                                     !
!rljiang@ssc.net.cn                                                                                                                !
!585 Guoshoujing Road. Pudong, Shanghai, P.R.C. 201203                                                                             !
!                                                                                                                                  !
!This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License         !
!as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.             !
!                                                                                                                                  !
!This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of    !
!MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.                        !
!                                                                                                                                  !
!You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software     !
!Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.                                                   !
!                                                                                                                                  !
!-------------------------------------------------------------LICENSE--------------------------------------------------------------!

!==================================================================================================================================|
subroutine integrate_sub (current)
!==================================================================================================================================|

   use parameters
   use block_define

   implicit none

   type(block), pointer, intent(inout) :: current

   integer(4) :: parent_id_p1
   type(block), pointer :: parent

!----------------------------------------------------------------------------------------------------------------------------------|
   if (current%nc .eq. 0) then
      call heat_conduction (current%ro, current%mx, current%my, current%mz,                                                        &
         current%bx, current%by, current%bz, current%en,                                                                           &
         thermal_amp, gm, current%dx, current%dy, min_dt_hc, nx_block, ny_block)
   endif

   parent => current%parent
   if (parent%lv .ge. 1 .and. parent%cpu_id .ne. cpu_id) then
      parent_id_p1 = parent%cpu_id + 1
      n_blocks_update_send(parent_id_p1) = n_blocks_update_send(parent_id_p1) + 1
      blocks_update_info_send(:, :, n_blocks_update_send(parent_id_p1), parent_id_p1) = current%id
      if (.not. parent%var_allocate_flag) then
         allocate (parent%ro(nx_block, ny_block), parent%mx(nx_block, ny_block), parent%my(nx_block, ny_block),                    &
                   parent%mz(nx_block, ny_block), parent%bx(nx_block, ny_block), parent%by(nx_block, ny_block),                    &
                   parent%bz(nx_block, ny_block), parent%en(nx_block, ny_block), parent%gx(nx_block, ny_block),                    &
                   parent%gy(nx_block, ny_block), parent%po(nx_block, ny_block), parent%az(nx_block, ny_block))
         if (ini_value_save_flag .ne. 0) then
            allocate (parent%ro0(nx_block, ny_block), parent%mx0(nx_block, ny_block), parent%my0(nx_block, ny_block),              &
               parent%mz0(nx_block, ny_block), parent%bx0(nx_block, ny_block), parent%by0(nx_block, ny_block),                     &
               parent%bz0(nx_block, ny_block), parent%en0(nx_block, ny_block), parent%az0(nx_block, ny_block))
         endif
         parent%var_allocate_flag = .true.
      endif
   endif

!----------------------------------------------------------------------------------------------------------------------------------|
   return
end subroutine integrate_sub
